package com.xjx.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Component
public class LogAspect {
//    private static final Logger logger = Logger.getLogger(Object.class);
    @Pointcut("execution(* com.xjx.service.impl.*.*(..))")
    public void pointcut(){

    }
    @Before("pointcut()")
    public void before(JoinPoint joinPoint){
        System.out.println("调用 " + joinPoint.getTarget().getClass().getName() + " 的 " + joinPoint.getSignature().getName()
                + " 方法。方法入参：" + Arrays.toString(joinPoint.getArgs()));
    }
    @AfterReturning(pointcut = "pointcut()",returning = "result")
    public void afterReturn(JoinPoint joinPoint,Object result){
        System.out.println("调用 " + joinPoint.getTarget().getClass().getName() + " 的 " + joinPoint.getSignature().getName()
                + " 方法。返回值是：" +  result);
    }
}
